{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.401000Z",
     "start_time": "2021-11-21T08:18:09.395000Z"
    }
   },
   "outputs": [],
   "source": [
    "import time\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.421000Z",
     "start_time": "2021-11-21T08:18:09.404000Z"
    }
   },
   "outputs": [],
   "source": [
    "class Warrior(object):\n",
    "    '''\n",
    "    战士职业的类\n",
    "    '''\n",
    "    def __init__(self, name): # 实例化的传入的名字\n",
    "        self.name = name\n",
    "        self.blood = 100\n",
    "        self.damage = 31\n",
    "        self.defance = 30\n",
    "        self.x = 0\n",
    "        self.y = 0\n",
    "    \n",
    "    def move(self):\n",
    "        # 移动\n",
    "        self.x += 1 \n",
    "        self.y += 1 \n",
    "        print('{name}移动到坐标:({x},{y})'.format(\n",
    "            name = self.name,\n",
    "            x = self.x,\n",
    "            y = self.y,\n",
    "            )\n",
    "         ) #这里的self.name就是获取我们传入的name\n",
    "        \n",
    "    def attack(self,targert):\n",
    "        # 发起攻击\n",
    "        targert.blood -= self.damage -  targert.defance\n",
    "#         targert.blood = targert.blood -  (self.damage -  targert.defance)\n",
    "        print('{name} 攻击 {targert} ，造成 {hurt} 点伤害。'.format(\n",
    "            name = self.name,\n",
    "            targert = targert.name,\n",
    "            hurt = self.damage -  targert.defance,\n",
    "            )\n",
    "         ) #这里的self.name就是获取我们传入的name\n",
    "       \n",
    "    def medicine(self):\n",
    "        # 恢复技能\n",
    "        blood = self.blood\n",
    "        if self.blood  < 60:\n",
    "            self.blood += 40\n",
    "            recover_point = 40\n",
    "        else:\n",
    "            self.blood = 100\n",
    "            recover_point = 100 - blood\n",
    "        print('{name} 恢复了 {point} 点生命。当前生命值: {blood}'.format(\n",
    "            name = self.name, \n",
    "            point = recover_point, \n",
    "            blood = self.blood,\n",
    "            )\n",
    "         )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.447000Z",
     "start_time": "2021-11-21T08:18:09.423000Z"
    }
   },
   "outputs": [],
   "source": [
    "class Assassin(Warrior):\n",
    "    def __init__(self, name): # 实例化的传入的名字\n",
    "        self.name = name\n",
    "        self.blood = 100\n",
    "        self.damage = 41\n",
    "        self.defance = 30\n",
    "        self.x = 0\n",
    "        self.y = 0\n",
    "        self.speed = 60\n",
    "        self.poisonous = False\n",
    "        self.attack_sum = 0\n",
    "        \n",
    "    def attention(self):\n",
    "        if self.damage>41:\n",
    "            pass\n",
    "        else:\n",
    "            self.damage += 10\n",
    "            print('{name}使用了 《专注》 技能，攻击力增加 10 '.format(name = self.name))\n",
    "        \n",
    "    def poison(self):\n",
    "        self.poisonous = True\n",
    "        print('{name}使用了 《淬毒》 技能 '.format(name = self.name))\n",
    "        \n",
    "    def attack(self,targert):\n",
    "        # 发起攻击\n",
    "        if self.poisonous == False:\n",
    "            targert.blood -= self.damage -  targert.defance\n",
    "            print('{name} 攻击 {targert} ，造成 {hurt} 点伤害。'.format(\n",
    "            name = self.name,\n",
    "            targert = targert.name,\n",
    "            hurt = self.damage -  targert.defance\n",
    "            )\n",
    "         ) #这里的self.name就是获取我们传入的name\n",
    "        else:\n",
    "            targert.blood -= self.damage -  targert.defance\n",
    "            print('{name} 攻击 {targert} ，造成 {hurt} 点伤害。'.format(name = self.name,targert = targert.name,hurt = self.damage -  targert.defance)) #这里的self.name就是获取我们传入的name\n",
    "            for i in range(3):\n",
    "                targert.blood -= 5\n",
    "                print('{name}使{targert}中毒，剩余{hurt}点血'.format(name = self.name,\n",
    "                targert = targert.name,\n",
    "                hurt=targert.blood))\n",
    "\n",
    "        self.attack_sum+=1\n",
    "\n",
    "        if self.attack_sum == 3 and self.damage>41:\n",
    "            self.damage-=10\n",
    "            self.attack_sum-=self.attack_sum\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.471000Z",
     "start_time": "2021-11-21T08:18:09.454000Z"
    }
   },
   "outputs": [],
   "source": [
    "aa = Warrior('aa')\n",
    "bb = Assassin('bb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.479000Z",
     "start_time": "2021-11-21T08:18:09.474000Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb使用了 《专注》 技能，攻击力增加 10 \n"
     ]
    }
   ],
   "source": [
    "bb.attention()\n",
    "bb.attention()\n",
    "bb.attention()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.513000Z",
     "start_time": "2021-11-21T08:18:09.494000Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "51"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bb.damage\n",
    "bb.attack_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:09.555000Z",
     "start_time": "2021-11-21T08:18:09.521000Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 21 点伤害。\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 21 点伤害。\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 21 点伤害。\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bb.attack(aa)\n",
    "bb.attack_sum\n",
    "\n",
    "bb.attack(aa)\n",
    "bb.attack_sum\n",
    "\n",
    "bb.attack(aa)\n",
    "bb.attack_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:18:21.977000Z",
     "start_time": "2021-11-21T08:18:21.970000Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 11 点伤害。\n",
      "bb 攻击 aa ，造成 11 点伤害。\n",
      "bb使用了 《专注》 技能，攻击力增加 10 \n",
      "bb 攻击 aa ，造成 21 点伤害。\n",
      "bb 攻击 aa ，造成 11 点伤害。\n",
      "bb 攻击 aa ，造成 11 点伤害。\n",
      "bb 攻击 aa ，造成 11 点伤害。\n",
      "bb 攻击 aa ，造成 11 点伤害。\n"
     ]
    }
   ],
   "source": [
    "bb.attack(aa)\n",
    "bb.attack(aa)\n",
    "\n",
    "bb.attention()\n",
    "bb.attack(aa)\n",
    "bb.attack(aa)\n",
    "bb.attack(aa)\n",
    "bb.attack(aa)\n",
    "bb.attack(aa)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-21T08:16:20.021000Z",
     "start_time": "2021-11-21T08:16:20.016000Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 21 点伤害。\n"
     ]
    }
   ],
   "source": [
    "bb.attack(aa)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bb.attack_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bb 攻击 aa ，造成 11 点伤害。\n"
     ]
    }
   ],
   "source": [
    "bb.attack(aa)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
